home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Macintosh Tracker 1.20 / source / Server⁄Tracker 4.0 / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-01  |  10.9 KB  |  507 lines  |  [TEXT/KAHL]

  1. /* display.c */
  2.  
  3. /* $Id: display.c,v 4.0 1994/01/11 17:45:22 espie Exp espie $
  4.  * $Log: display.c,v $
  5.  * Revision 4.0  1994/01/11  17:45:22  espie
  6.  * Major change: does not use sprintf heavily.
  7.  *
  8.  * Revision 1.9  1994/01/09  17:36:22  Espie
  9.  * Generalized open.c.
  10.  *
  11.  * Revision 1.8  1994/01/08  03:55:43  Espie
  12.  * Use name_of_note(), no need for run_in_fg().
  13.  *
  14.  * Revision 1.7  1994/01/08  02:04:21  Espie
  15.  * Small bug: strcpy -> stringcopy.
  16.  *
  17.  * Revision 1.6  1994/01/07  15:06:26  Espie
  18.  * Cond code to make show/not show robust.
  19.  *
  20.  * Revision 1.5  1994/01/06  22:32:42  Espie
  21.  * Added instrument name as shown per display.c.
  22.  *
  23.  * Revision 1.4  1994/01/05  14:54:09  Espie
  24.  * *** empty log message ***
  25.  *
  26.  * Revision 1.3  1994/01/05  01:59:14  Espie
  27.  * Added prototypes.
  28.  *
  29.  * Revision 1.2  1993/12/28  13:54:44  Espie
  30.  * Major change: use scroller interface.
  31.  *
  32.  * Revision 1.1  1993/12/26  00:55:53  Espie
  33.  * Initial revision
  34.  *
  35.  * Revision 1.8  1993/12/04  16:12:50  espie
  36.  * Lots of LOCAL added + minor changes.
  37.  *
  38.  * Revision 1.7  1993/12/02  15:45:33  espie
  39.  * Try to get rid of %d format in printf.
  40.  *
  41.  * Revision 1.6  1993/11/17  15:31:16  espie
  42.  * *** empty log message ***
  43.  *
  44.  * Revision 1.4  1993/07/18  10:39:44  espie
  45.  * Added last displays.
  46.  *
  47.  * Revision 1.3  1993/07/17  22:23:41  espie
  48.  * Fixed bug with bad loops.
  49.  *
  50.  * Revision 1.2  1993/07/17  12:00:30  espie
  51.  * Added other commands (numerous).
  52.  *
  53.  */
  54.      
  55. #include <stdio.h>
  56. #include <string.h>
  57.      
  58. #include "defs.h"
  59. #include "song.h"
  60. #include "channel.h"
  61. #include "extern.h"
  62. #include "tags.h"
  63. #include "prefs.h"
  64.  
  65. ID("$Id: display.c,v 4.0 1994/01/11 17:45:22 espie Exp espie $")
  66. LOCAL void init_display P((void));
  67. LOCAL void (*INIT)P((void)) = init_display;
  68.      
  69. #define ENTRY_SIZE 14
  70. LOCAL char buffer[80];
  71. LOCAL char *base;
  72.  
  73. LOCAL char *num[] = {
  74. " 0", " 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9",
  75. "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
  76. "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
  77. "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
  78. "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
  79. "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
  80. "60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
  81. "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
  82. "80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
  83. "90", "91", "92", "93", "94", "95", "96", "97", "98", "99",
  84. "00", "01", "02", "03", "04", "05", "06", "07", "08", "09"};
  85.  
  86. char instname[] = { ' ', '1', '2', '3', '4', '5', '6', '7', '9',
  87. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  88. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  89.  
  90. LOCAL void reset_buffer()
  91.    {
  92.    base = new_scroll();
  93.    }
  94.  
  95. LOCAL void next_entry()
  96.    {
  97.    base += ENTRY_SIZE;
  98.    }
  99.  
  100. LOCAL void copy1(to, from)
  101. char *to, *from;
  102.    {
  103.    *to = *from;
  104.    }
  105.    
  106. LOCAL void copy2(to, from)
  107. char *to, *from;
  108.    {
  109.    *to++ = *from++;
  110.    *to = *from;
  111.    }
  112.  
  113. LOCAL void copy3(to, from)
  114. char *to, *from;
  115.    {
  116.    *to++ = *from++;
  117.    *to++ = *from++;
  118.    *to = *from;
  119.    }
  120.  
  121. LOCAL void stringcopy(to, from)
  122. char *to, *from;
  123.    {
  124.    while (*from)
  125.       *to++ = *from++;
  126.    }
  127.  
  128. LOCAL void num2(to, n)
  129. char *to;
  130. int n;
  131.    {
  132.    char *v = num[n];
  133.    *to++ = *v++;
  134.    *to = *v;
  135.    }
  136.  
  137. LOCAL void num3(to, n)
  138. char *to;
  139. int n;
  140.    {
  141.    char *v;
  142.  
  143.    if (n >= 100)
  144.       *to = "0123456789"[n/100];
  145.    while (n > 109)
  146.       n -= 100;
  147.    v = num[n];
  148.    to++;
  149.    *to++ = *v++;
  150.    *to = *v;
  151.    }
  152.  
  153. LOCAL char *id = "$Id: display.c,v 4.0 1994/01/11 17:45:22 espie Exp espie $";
  154.      
  155. LOCAL void (*table[NUMBER_EFFECTS]) P((int samp, int para, int note, struct channel *ch));
  156.  
  157. LOCAL void disp_default(samp, para, note, ch)
  158. int samp, para, note;
  159. struct channel *ch;
  160.    {
  161.    copy3(base+2, name_of_note(note));
  162.    }
  163.  
  164. LOCAL void disp_speed(samp, para, note, ch)
  165. int samp, para, note;
  166. struct channel *ch;
  167.    {
  168.    copy3(base+2, name_of_note(note));
  169.    if (para < 32)
  170.       {
  171.       stringcopy(base+6, "SPD");
  172.       num2(base+10, para);
  173.       }
  174.    else
  175.       {
  176.       stringcopy(base+6, "spd%");
  177.       num3(base+10, para * 100/NORMAL_FINESPEED);
  178.       }
  179.    }
  180.  
  181. LOCAL void disp_nothing(samp, para, note, ch)
  182. int samp, para, note;
  183. struct channel *ch;
  184.    {
  185.    }
  186.  
  187. LOCAL void disp_portamento(samp, para, note, ch)
  188. int samp, para, note;
  189. struct channel *ch;
  190.    {
  191.    stringcopy(base+2, "-->");
  192.    copy3(base+5, name_of_note(note));
  193.    if (para)
  194.       {
  195.       base[8] = '(';
  196.       num3(base+9, para);
  197.       base[12] = ')';
  198.       }
  199.    }
  200.  
  201. LOCAL void disp_portaslide(samp, para, note, ch)
  202. int samp, para, note;
  203. struct channel *ch;
  204.    {
  205.    stringcopy(base+2, "-->");
  206.    copy3(base+5, name_of_note(note));
  207.    if (LOW(para))
  208.       {
  209.       base[9] = '-';
  210.       num2(base+10, LOW(para));
  211.       }
  212.    else
  213.       {
  214.       base[9] = '+';
  215.       num2(base+10, HI(para));
  216.       }
  217.    }
  218.  
  219. LOCAL void disp_upslide(samp, para, note, ch)
  220. int samp, para, note;
  221. struct channel *ch;
  222.    {
  223.    copy3(base+2, name_of_note(note));
  224.    base[8] = '-';
  225.    if (para)
  226.       num3(base+9, para);
  227.    }
  228.  
  229. LOCAL void disp_downslide(samp, para, note, ch)
  230. int samp, para, note;
  231. struct channel *ch;
  232.    {
  233.    copy3(base+2, name_of_note(note));
  234.    base[8] = '+';
  235.    if (para)
  236.       num3(base+9, para);
  237.    }
  238.  
  239. LOCAL void disp_vibrato(samp, para, note, ch)
  240. int samp, para, note;
  241. struct channel *ch;
  242.    {
  243.    copy3(base+2, name_of_note(note));
  244.    copy2(base+6, "vb");
  245.    if (para)
  246.       {
  247.       num2(base+8, LOW(para));
  248.       base[10] = '/';
  249.       num2(base+11, HI(para));
  250.       }
  251.    }
  252.  
  253. LOCAL void disp_vibratoslide(samp, para, note, ch)
  254. int samp, para, note;
  255. struct channel *ch;
  256.    {
  257.    copy3(base+2, name_of_note(note));
  258.    stringcopy(base+6, "vibs");
  259.    if (LOW(para))
  260.       {
  261.       base[10] = '-';
  262.       num2(base+11, LOW(para));
  263.       }
  264.    else
  265.       {
  266.       base[10] = '+';
  267.       num2(base+11, HI(para));
  268.       }
  269.    }
  270.  
  271. LOCAL void disp_slidevol(samp, para, note, ch)
  272. int samp, para, note;
  273. struct channel *ch;
  274.    {
  275.    copy3(base+2, name_of_note(note));
  276.    stringcopy(base+6, "vol");
  277.    if (LOW(para))
  278.       {
  279.       base[10] = '-';
  280.       num2(base+11, LOW(para));
  281.       }
  282.    else
  283.       if (HI(para))
  284.          {
  285.          base[10] = '+';
  286.          num2(base+11, HI(para));
  287.          }
  288.    }
  289.  
  290. LOCAL void disp_volume(samp, para, note, ch)
  291. int samp, para, note;
  292. struct channel *ch;
  293.    {
  294.    copy3(base+2, name_of_note(note));
  295.    if (para)
  296.       {
  297.       stringcopy(base+6, "vol");
  298.       num3(base+10, para);
  299.       }
  300.    else
  301.       stringcopy(base+6, "silent");
  302.    }
  303.  
  304. LOCAL void disp_arpeggio(samp, para, note, ch)
  305. int samp, para, note;
  306. struct channel *ch;
  307.    {
  308.    if (note != NO_NOTE)
  309.       {
  310.       copy3(base+2, name_of_note(note));
  311.       copy3(base+6, name_of_note(note + LOW(para)));
  312.       copy3(base+10, name_of_note(note + HI(para)));
  313.       }
  314.    else
  315.       if (ch->note == NO_NOTE)
  316.          stringcopy(base, "Arp error");
  317.       else
  318.          {
  319.          copy3(base+6, name_of_note(ch->note + LOW(para)));
  320.          copy3(base+10, name_of_note(ch->note + HI(para)));
  321.          }  
  322.    }
  323.  
  324. LOCAL void disp_retrig(samp, para, note, ch)
  325. int samp, para, note;
  326. struct channel *ch;
  327.    {
  328.    copy3(base+2, name_of_note(note));
  329.    stringcopy(base + 6, "rtg");
  330.    num3(base+9, para);
  331.    }
  332.  
  333. LOCAL void disp_note_cut(samp, para, note, ch)
  334. int samp, para, note;
  335. struct channel *ch;
  336.    {
  337.    copy3(base+2, name_of_note(note));
  338.    stringcopy(base+6, "cut");
  339.    num3(base+9, para);
  340.    }
  341.  
  342. LOCAL void disp_late_start(samp, para, note, ch)
  343. int samp, para, note;
  344. struct channel *ch;
  345.    {
  346.    copy3(base+2, name_of_note(note));
  347.    stringcopy(base+6, "lte");
  348.    num3(base+9, para);
  349.    }
  350.  
  351. LOCAL void disp_offset(samp, para, note, ch)
  352. int samp, para, note;
  353. struct channel *ch;
  354.    {
  355.    copy3(base+2, name_of_note(note));
  356.    stringcopy(base+6, "off   %");
  357.    num3(base+9, para * 25600/ch->samp->length);
  358.    }
  359.  
  360. LOCAL void disp_smooth_up(samp, para, note, ch)
  361. int samp, para, note;
  362. struct channel *ch;
  363.    {
  364.    copy3(base+2, name_of_note(note));
  365.    stringcopy(base+6, "sth-");
  366.    num3(base+10, para);
  367.    }
  368.  
  369. LOCAL void disp_smooth_down(samp, para, note, ch)
  370. int samp, para, note;
  371. struct channel *ch;
  372.    {
  373.    copy3(base+2, name_of_note(note));
  374.    stringcopy(base+6, "sth+");
  375.    num3(base+10, para);
  376.    }
  377.  
  378. LOCAL void disp_smooth_upvolume(samp, para, note, ch)
  379. int samp, para, note;
  380. struct channel *ch;
  381.    {
  382.    copy3(base+2, name_of_note(note));
  383.    stringcopy(base+8, "++");
  384.    num3(base+10, para);
  385.    }
  386.  
  387. LOCAL void disp_smooth_downvolume(samp, para, note, ch)
  388. int samp, para, note;
  389. struct channel *ch;
  390.    {
  391.    copy3(base+2, name_of_note(note));
  392.    stringcopy(base+8, "--");
  393.    num3(base+10, para);
  394.    }
  395.  
  396. LOCAL void disp_change_finetune(samp, para, note, ch)
  397. int samp, para, note;
  398. struct channel *ch;
  399.    {
  400.    copy3(base+2, name_of_note(note));
  401.    stringcopy(base+6, "fine");
  402.    num2(base+11, para);
  403.    }
  404.  
  405. LOCAL void disp_skip(samp, para, note, ch)
  406. int samp, para, note;
  407. struct channel *ch;
  408.    {
  409.    copy3(base+2, name_of_note(note));
  410.    if (para)
  411.       {
  412.       stringcopy(base+6, "skp");
  413.       num3(base+10, para);
  414.       }
  415.    else
  416.       stringcopy(base+6, "next");
  417.    }
  418.  
  419. LOCAL void disp_fastskip(samp, para, note, ch)
  420. int samp, para, note;
  421. struct channel *ch;
  422.    {
  423.    copy3(base+2, name_of_note(note));
  424.    stringcopy(base+6, "ff");
  425.    num3(base+10, para);
  426.    }
  427.  
  428. LOCAL void disp_loop(samp, para, note, ch)
  429. int samp, para, note;
  430. struct channel *ch;
  431.    {
  432.    copy3(base+2, name_of_note(note));
  433.    if (para == 0)
  434.       stringcopy(base+6, "SETLOOP");
  435.    else
  436.       {
  437.       stringcopy(base+6, "LOOP");
  438.       num3(base+10, para);
  439.       }
  440.    }
  441.  
  442. LOCAL void disp_delay_pattern(samp, para, note, ch)
  443. int samp, para, note;
  444. struct channel *ch;
  445.    {
  446.    copy3(base+2, name_of_note(note));
  447.    stringcopy(base+6, "DLAY");
  448.    num3(base+10, para);
  449.    }
  450.  
  451. #define disp_nothing disp_default
  452.  
  453. LOCAL void init_display()
  454.    {
  455.    int i;
  456.  
  457.    for (i = 0; i < NUMBER_EFFECTS; i++)
  458.       table[i] = disp_nothing;
  459.    table[EFF_ARPEGGIO] = disp_arpeggio;
  460.    table[EFF_SPEED] = disp_speed;
  461.    table[EFF_SKIP] = disp_skip;
  462.    table[EFF_FF] = disp_fastskip;
  463.    table[EFF_VOLUME] = disp_volume;
  464.    table[EFF_VOLSLIDE] = disp_slidevol;
  465.    table[EFF_OFFSET] = disp_offset;
  466.    table[EFF_PORTA] = disp_portamento;
  467.    table[EFF_PORTASLIDE] = disp_portaslide;
  468.    table[EFF_UP] = disp_upslide;
  469.    table[EFF_DOWN] = disp_downslide;
  470.    table[EFF_VIBRATO] = disp_vibrato;
  471.    table[EFF_VIBSLIDE] = disp_vibratoslide;
  472.    table[EFF_SMOOTH_UP] = disp_smooth_up;
  473.    table[EFF_SMOOTH_DOWN] = disp_smooth_down;
  474.    table[EFF_CHG_FTUNE] = disp_change_finetune;
  475.    table[EFF_LOOP] = disp_loop;
  476.    table[EFF_RETRIG] = disp_retrig;
  477.    table[EFF_S_UPVOL] = disp_smooth_upvolume;
  478.    table[EFF_S_DOWNVOL] = disp_smooth_downvolume;
  479.    table[EFF_NOTECUT] = disp_note_cut;
  480.    table[EFF_LATESTART] = disp_late_start;
  481.    table[EFF_DELAY] = disp_delay_pattern;
  482.    reset_buffer();
  483.    }
  484.  
  485. void dump_event(ch, e)
  486. struct channel *ch;
  487. struct event *e;
  488.    {
  489.    INIT_ONCE;
  490.    
  491.    if (get_pref_scalar(PREF_SHOW))
  492.       {
  493.       if (ch && base)
  494.          {
  495.          *base = instname[e->sample_number];
  496.          (*table[e->effect])(e->sample_number, e->parameters, e->note, ch);
  497.          next_entry();
  498.          }
  499.       else
  500.          {
  501.          scroll();
  502.          reset_buffer();
  503.          }
  504.       }
  505.    }
  506.  
  507.